// client/ClientBatch控制器
define('clientClientBatchController', ['angular','jquery','underscore'], function (angular,$,_) {
    var module = angular.module('controllers');
    module.controller('clientClientBatchController', ['$scope','$route','$location','$rootScope','businessServers','$filter', function ($scope,$route,$location,$rootScope,businessServers,$filter) {
    	$scope.addClientBatchData=[{name:"",sex:"",phone:"",qq:"",business_type:1}];
        $scope.addClientBatch=function(){
            var user={name:"",sex:"",phone:"",qq:"",business_type:1};
            $scope.addClientBatchData.push(user);
        };
        $scope.delClientBatch=function(v){
            if($scope.addClientBatchData.length>1){
            $scope.addClientBatchData=_.without($scope.addClientBatchData,v);
            }
        };
        $scope.clientBatchForm=function(valid){
            $scope.allData=[];
            for (var i = 0; i < $scope.addClientBatchData.length; i++) {
                $scope.allData.push(angular.extend($scope.addClientBatchData[i],$scope.formData));
            }
            if(valid){
                businessServers.addMultitermBusiness(angular.toJson($scope.allData),$rootScope.user.company).then(function (data) {
                    if(data){
                        $location.path('/Main/main');
                    }else{
                        alert("添加失败");
                    }
                });
            }else{
                alert("请填写全部信息");
            }
        };
    }]); 
});